package com.mxx.common.security.displacer;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @Author itzgyw
 * @Date 2020-02-24
 * @Time 0:24
 * @Description:
 */
public class Base64Displacer implements Displacer {
    private final Charset charset;

    public Base64Displacer() {
        this.charset = StandardCharsets.UTF_8;
    }

    public Base64Displacer(Charset charset) {
        this.charset = charset;
    }

    @Override
    public byte[] encoder(byte[] bytes) {
        return Base64.getEncoder().encode(bytes);
    }


    @Override
    public byte[] decoder(byte[] bytes) {
        return  Base64.getDecoder().decode(bytes);
    }


    @Override
    public Charset getCharset() {
        return this.charset;
    }
}
